Next | Prev | Up | Top | Contents | Index

Using Typedefs

This section describes typedefs that you can use to write portable code for a range of target environments, including 32- and 64-bit workstations as well as 16- and 32-bit PCs. These typedefs are enabled by compiler-predefined macros (listed in Table 7-2), and are in the file inttypes.h. (This discussion applies to C, although the same macros are predefined by the C++ compiler.)

Portability problems exist because an int (32 bits) is no longer the same size as a pointer (64 bits) and a long (64 bits) in 64-bit programs. Typedefs free you from having to know the underlying compilation model or worry about type sizes. In the future, if that model changes, the code should still work.

Typically, you want source code that you can compile either in 32- or 64-bit mode. (In this discussion, 32-bit mode means -mips1 or -mips2; 64-bit mode means -mips3 or -mips4.)

The following typedefs are defined in inttypes.h:

typedef signed char   int8_t;
typedef unsigned char   uint8_t;
typedef signed short  int16_t;
typedef unsigned short  uint16_t;
typedef signed int  int32_t;
typedef unsigned int  uint32_t;
typedef signed long long int  int64_t;
typedef unsigned long long int  uint64_t;
typedef signed long long int  intmax_t;
typedef unsigned long long int  uintmax_t;
typedef signed long int  intptr_t;
typedef unsigned long int  uintptr_t;
intmax_t and uintmax_t are guaranteed to be the largest integer type supported by this implementation. Use them in code that must be able to deal with any integer value.

intptr_t and uintptr_t are guaranteed to be exactly the size of a pointer.


Next | Prev | Up | Top | Contents | Index